<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var average = function(salary) {
    var salary=[4000,3000,1000,2000]
    let max=salary[0]
    let min=salary[0]
    let sum=0
    let average=0
    for(let i=0;i<salary.length;i++){
        if(max<salary[i]){
            max=salary[i]
        }
        if(min>salary[i]){
            min=salary[i]
        }
        sum+=salary[i]
    }
    average=(sum-max-min)/(salary.length-2)
    console.log(average)
};

</script>
</html>
        Arrays.sort(salary);
        double average=0;
        int max=salary[0];
        int min=salary[0];
        int sum=0;
        int x=salary.length-2;
        for(int i=0;i<salary.length;i++){
        sum+=salary[i];
        if(max<salary[i]){
            max=salary[i];
        }
        if(min>salary[i]){
            min=salary[i];
        }
    }
    average=(sum-max-min)/x;
    return average;


    

